package com.way.controller;

import com.way.common.core.domain.R;
import com.way.domain.dto.SysUserDto;
import com.way.domain.vo.SysUserVo;
import com.way.service.SysUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "用户管理")
@RequestMapping("user")
@RestController
public class SysUserController {

    @Resource
    private SysUserService service;

    @Operation(summary = "查询全部")
    @GetMapping("/")
    public R<List<SysUserVo>> findAll() {
        List<SysUserVo> data = service.findAll();
        return R.ok(data);
    }

    @Operation(summary = "按ID查找")
    @GetMapping("/{id}")
    public R<SysUserVo> findById(@Parameter(description = "用户ID") @PathVariable("id") Integer id) {
        SysUserVo data = service.findById(id);
        return R.ok(data);
    }

    @Operation(summary = "保存")
    @PostMapping("/")
    public R<Void> save(@RequestBody SysUserDto dto) {
        service.save(dto);
        return R.ok();
    }

    @Operation(summary = "删除")
    @DeleteMapping("/{id}")
    public R<Void> delete(@Parameter(description = "用户ID") @PathVariable("id") Integer id) {
        service.delete(id);
        return R.ok();
    }

}
